package com.cn.yygh.common.exception;

import com.cn.yygh.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)   //指定什么异常
    @ResponseBody       //使结果以json形式输出
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    /*
    自定义异常
     */
    @ExceptionHandler(YyghException.class)
    @ResponseBody
    public Result error(YyghException e){
        e.printStackTrace();
        return Result.fail();
    }
}
